from setting import *

# 敌人飞机

class EnemyPlane(pygame.sprite.Sprite):
    # 初始化敌人飞机
    def __init__(self):
        self._layer = 2
        self.groups = allgroup,enemygroup
        pygame.sprite.Sprite.__init__(self,self.groups)
        self.image = pygame.image.load('./images/enemy/enemy0.png')
        self.rect = self.image.get_rect()
        self.HP = 1
        self.speed = 2
        self.x_speed = 0
        self.y_speed = 2
   

    
    # 设置飞机位置
    def set_pos(self, x, y):
        self.rect.x = x
        self.rect.y = y

    def update(self):
        """ 
        更新位置
            计算位置，精灵组自动调用
            超出屏幕，自毁
        """
        self.rect.x += self.x_speed
        self.rect.y += self.y_speed
        if self.HP <= 0:
            self.kill()
        if not self.rect.colliderect(SCENERECT):
            self.kill()

